﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace MenuGame2DXNA
{
    public class TimeLine : VisibleGameEntity
    {
        private int Time;
        private float Distance;
        public bool End { get; set; } 
        float  width;
        private bool Gan = false;
        public TimeLine(Game _game,int time)
        {
            ObjectVisible = new List<Sprite>();
            Texture2D[] _texture = new Texture2D[2];
            _texture[0] = _game.Content.Load<Texture2D>("TimeXanh");
            _texture[1] = _game.Content.Load<Texture2D>("TimeDo");
            Sprite temp = new UserControlledSprite(_texture, new Vector2(0, 0));
           
            width = 495;
            temp.Size = new Vector2(width, 29);
            
            ObjectVisible.Add(temp);
         
            nObjectVisible = 1;
            Time = time;
           
            Distance = ObjectVisible[0].Size.X / ((Time * 1000) / 16);
            End = false;
        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Color color)
        {
            float widthnew  = ObjectVisible[0].Size.X - Distance;
            ObjectVisible[0].Size = new Vector2(widthnew, ObjectVisible[0].Size.Y);
           
            if (widthnew <= 0)
            {
                End = true;
                
            }
            else if (widthnew < width / 3 && !Gan)
            {
                ObjectVisible[0].SetFrame(0, 1,false);
               
                Gan = true;
            }
            base.Update(gameTime, color);
        }
       
    }
}
